package cn.hoofungson.sso;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

import javax.sql.DataSource;

@EnableAutoConfiguration
@SpringBootApplication
@ImportResource("classpath:config/applicationContext.xml")
public class SsoApplication extends ServletInitializer {

	private static final Log log = LogFactory.getLog(SsoApplication.class);

	public static void main(String[] args) {
		SpringApplication.run(SsoApplication.class, args);
		log.info("====================== SSO 启动成功!======================");
	}

	/**
	 * 使用 DruidDataSource，1.3+ spring boot 可直接使用配置文件配置
	 * @return
	 */
	@Bean
	@ConfigurationProperties("spring.datasource")
	public DataSource dataSource() {
		return DataSourceBuilder.create().type(ComboPooledDataSource.class)
				.build();
	}

}
